//
// Created by Huafv on 2024/10/11.
//
#include <stdio.h>
#include "ringbuffer.h"

#define BUFFER_SIZE (256)
struct ringbuffer ring_buf;
uint8_t buffer[BUFFER_SIZE] = { 0 };

int main(){
    uint32_t read_len = 0;
    uint32_t write_len = 0;
    uint8_t  read_data[128] = { 0 };
    uint8_t  write_data[128] = { 0 };

    for (int i = 0; i < sizeof(write_data) ; ++i) {
        write_data[i] = i;
    }

    /* init ringbuffer */
    ringbuffer_init(&ring_buf, buffer, BUFFER_SIZE);

    /* ringbuffer is Null to get data */
    read_len = ringbuffer_get(&ring_buf, read_data, sizeof(read_data));
    ringbuffer_print_data(&ring_buf);
    printf("read_len %d\r\n", read_len);

    /* put to ringbuffer */
    write_len = ringbuffer_put(&ring_buf, write_data, sizeof(write_data));
    ringbuffer_print_data(&ring_buf);
    printf("write_len %d\r\n", write_len);

    read_len = ringbuffer_get(&ring_buf, read_data, (5));
    ringbuffer_print_data(&ring_buf);
    printf("read_len %d\r\n", read_len);

    read_len = ringbuffer_get(&ring_buf, read_data, (200));
    ringbuffer_print_data(&ring_buf);
    printf("read_len %d\r\n", read_len);

    return 0;
}